package leecode;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class Question163 {
    public int majorityElement(int[] nums) {

        if (nums.length < 2) {
            return nums[0];
        }
        Map<Integer, Integer> hash = new HashMap<>();
        for (int num : nums) {
            Integer val = hash.getOrDefault(num, 0);
            if (val + 1 > (nums.length >>1)) {
                return num;
            }
            hash.put(num, val + 1);
        }
        return 0;
    }
    @Test
    public void main() {
        int[] ints = {2,2,1,1,1,2,2};
        System.out.println(ints.length>>1);
    }
}
